package com.spring.sunflower.main.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.AnchorDetailBean;
import com.spring.sunflower.bean.BannerBean;
import com.spring.sunflower.main.MainContract;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/6/2<br/>
 * <p>
 * Describe:<br/>
 */
public class MePresenter extends BasePresenter<MainContract.MeView> {
    private String TAG = "MainPresenter";

    public MePresenter(MainContract.MeView baseView) {
        super(baseView);
    }

    public void getDetail(String targetId) {
        LogUtils.wTag("BasePresenter","targetId="+targetId);
        Observable<AnchorDetailBean> observable = requestDataSource.requestAnchorDetail(targetId);
        addDisposable(observable, new BaseObserver<AnchorDetailBean>(baseView) {

            @Override
            public void onSuccess(AnchorDetailBean bean) {
                LogUtils.dTag(TAG, "onSuccess="+ bean.toString());
                AnchorDetailBean.DatasBean datas = bean.getDatas();
                baseView.hideLoading();
                baseView.showData(datas);
            }

            @Override
            public void onError(int status, String msg) {
                LogUtils.dTag(TAG, "onSuccess="+status+"====msg");
            }
        });
    }

    public void getBanner() {
        Observable<BannerBean> observable = requestDataSource.requestBanner();
        addDisposable(observable, new BaseObserver<BannerBean>() {

            @Override
            public void onSuccess(BannerBean bean) {
                baseView.showBannerData(bean.getDatas());

            }

            @Override
            public void onError(int status, String msg) {
                baseView.showError(msg);
            }
        });
    }
}
